//
// Created by Suzhen on 2016/12/13.
//

#ifndef ORIONV2_UTILS_H
#define ORIONV2_UTILS_H

#include "Orion.h"

ORION_V2_NAMESPACE_BEGIN

        namespace Utils {


            extern std::string sformat_impl_(boost::format &f);

            template<typename FirstType, typename... Arg>
            std::string sformat_impl_(boost::format &f, FirstType &&first, Arg &&... arg) {
                return sformat_impl_(f % std::forward<FirstType>(first),
                                     std::forward<Arg>(arg)...);
            }

            template<typename... Arg>
            std::string sformat(const std::string &fmt, Arg &&... arg) {
                auto formatter = boost::format(fmt);
                return sformat_impl_(formatter, std::forward<Arg>(arg)...);
            }

            inline std::size_t GetCoreNum() {
                return std::thread::hardware_concurrency();
            }

            inline std::size_t GetServerClusterSuggestSize() {
                return GetCoreNum() - 1;
            }

            extern void CloseUvLoop(uv_loop_t *l);

            inline void InitSockAddr(const std::string &bindAddr, int bindPort, sockaddr_in &addr) {
                uv_ip4_addr(bindAddr.c_str(), bindPort, &addr);
            }
            
            extern void bindThread2CpuByIndex(std::size_t idx);
        };

ORION_V2_NAMESPACE_END


#endif //ORIONV2_UTILS_H
